<?php

function handleTable($entity, $item, $mode){
	
		if(isOpenCompleteTag($item, 'TABLE')){
			array_push($mode, 'TABLE');
			echo "<table>";
		}
		
		if(isCompleteTag($item, 'TABLETITLE')){
			$param = $item['attributes'];
			$left = $param['LEFT'];
			$center = $param['CENTER']; 
			$right = $param['RIGHT'];
			
			echo "<tr><td><table class='innertable'><tr>";
				if($left){
					echo "<td class='header1'>".handle($left, $entity)."</td>";
				}
				if($center){
					echo "<td align='center' class='header2'>".handle($center, $entity)."</td>";
				}
				if($right){
					echo "<td align='right' class='header2'>".handle($right, $entity)."</td>";
				}
			echo "</tr></table></td></tr>";
		}
		
		if(isCompleteTag($item, 'TABLEHEADER')){
			echo "<tr><td><table id='mytable'><thead><tr>";
			$param = $item['attributes'];
			if($param['LOOP'] && $param['LINK']){
				$loop = handle($param['LOOP'], $entity);
				for($i=0; $i<sizeof($loop);$i++){
					echo "<td class='header3'>".$loop[$i]."</td>";
				}
				
				$link = handle($param['LINK'], $entity);
			}
			echo "</tr></thead>";
		}
		
		if(isCompleteTag($item, 'TABLELIST')){
			$objList = get_entity_records_obj($entity);
			echo "<tbody>";		
			foreach($objList as $obj){
				$params = $obj->get_params();
				echo "<tr class='clickDetail' onclick=window.open('index.php?page=detail&entity=".$entity."&".$obj->get_access_string()."','_self')>";
					foreach($params as $param){
						echo "<td>".$param->get_valueDisplay()."</td>";
					}
				echo "</tr>";
			}
			echo "</tbody>";
		}
		
		if(isCompleteTag($item, 'TABLEDETAIL')){
			$objList = get_entity_records_obj($entity);
			echo "<tbody>";		
			foreach($objList as $obj){
				$params = $obj->get_params();
				foreach($params as $param){
					echo "<tr>";
						echo "<td class='header3'>".$param->get_display()."</td>";
						echo "<td>".$param->get_value()."</td>";
					echo "</tr>";
				}
			}
			echo "</tbody>";
		}
						
		if(isCloseTag($item, 'TABLE')){
			echo "</table></td></tr>";
			array_pop($mode);
			echo "</table>";
			
		}
		
	return $mode;
}

?>